package chpt08;

import java.io.Console;
import java.util.Arrays;
import java.io.IOException;

public class Password {
    
    public static void main (String args[]) throws IOException {

        Console c = System.console();
        if (c == null) {
        	System.err.println("控制台错误！");
            System.exit(1);
        }
        do {
	        String user = c.readLine("用户名： ");
	        char[] pwd = c.readPassword("密码：");
	        if (!verify(user, pwd)) {
	        	c.format("密码错误，请重新输入！%n");
	        }else
	        	break; 
        }while (true);
        c.format("登录成功！%n");
    }
    
    static boolean verify(String user, char[] pwd) {
    	String userid = "admin";
    	char[] password = {'1','2','3','4','5','6'};
    	if (user.equals(userid) && Arrays.equals(password, pwd)) {
    		return true;
    	}
       return false;
    }
}